(C) 1996 AROS - The Amiga Replacement OS


NAME
#include <proto/utility.h>
LONG SMult32()
SYNOPSIS
LONG arg1
LONG arg2

LOCATION
In UtilityBase at offset 23
FUNCTION
Performs the signed 32-bit multiplication of arg1 * arg2 and returns a signed 32 bit value.

INPUTS
arg1, arg2 - 32 bit signed longs
RESULT
arg1 * arg2

NOTES
This can perform the multiplication either using the machines native instructions (if they exist), or in software using a simple algorithm based on expanding algebraic products.

The utility.library math functions are unlike all other utility functions in that they don't require the library base to be loaded in register A6, and they also save the values of the address registers A0/A1.

This function is mainly to support assembly programers, and is probably of limited use to higher-level language programmers.

EXAMPLE
LONG a = 352543;
LONG b = -52464;
LONG c = SMult32(a,b);
c == -1315946768

BUGS
Of limited use to C programmers.

SEE ALSO
UMult32(), UMult64(), SMult64()
INTERNALS
May be handled by code in config/$(KERNEL), may not be... It is for m68k-native.

For emulation we are performing the operation:

(2^16 * a + b) * (2^16 * c + d) = 2^32 * ab + 2^16 * ad + 2^16 * bc + bd = 2^32 * ab + 2^16 ( ad + bc ) + bd

Now since the result is a 32-bit number, the 2^32 term will have no effect. (Since 2^32 > max (32-bit number)), as will the high part of ad + bc.

Therefore: product = 2^16( ad + bc ) + bd

HISTORY
03.02.1997 ldp
machine.i in local directory
02.02.1997 iaint
Special assembly support code for m68k/Amiga compatibility